package com.javasm.finance.controller;

import com.javasm.finance.entity.CodeAndMsg;
import com.javasm.finance.entity.ReturnEntity;
import com.javasm.finance.util.RespUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/logout")
public class LogoutController extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //移除session对象值
        HttpSession session = req.getSession();
        session.removeAttribute("user");
        session.removeAttribute("loginUserMenuUrl");
        session.removeAttribute("menuList");
        //设置响应数据
        ReturnEntity re = new ReturnEntity();
        re.setReturnCode(CodeAndMsg.LOGOUT_SUCCESS.getReturnCode());
        re.setReturnMsg(CodeAndMsg.LOGOUT_SUCCESS.getReturnMsg());
        //写出响应数据
        RespUtils.handleResp(resp, re);
    }
}
